package com.ll.oss.controller;

import com.ll.commonUtils.R;
import com.ll.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 2020/10/23 - 11:34
 */
@Api(description = "文件上传API") //swagger界面提示
@RestController
@RequestMapping("/eduoss/fileoss")
//@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    //上传头像的方法
    @ApiOperation(value = "上传头像") //swagger界面提示
    @PostMapping
    public R uploadOssFile(MultipartFile file){
        //获取上传文件
        //返回上传到oss的路径
        String fileUrl = ossService.uploadFileAvatar(file);

        if (StringUtils.isEmpty(fileUrl)){
            return R.error().message("上传文件失败");
        }else {
            return R.ok().data("url", fileUrl);
        }
    }

}
